home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / app / brush_select_cmds.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-04  |  7.5 KB  |  319 lines

  1. /* The GIMP -- an image manipulation program
  2.  * Copyright (C) 1995-2000 Spencer Kimball and Peter Mattis
  3.  *
  4.  * This program is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 2 of the License, or
  7.  * (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17.  */
  18.  
  19. /* NOTE: This file is autogenerated by pdbgen.pl. */
  20.  
  21. #include "config.h"
  22.  
  23. #include "procedural_db.h"
  24.  
  25. #include <string.h>
  26.  
  27. #include "apptypes.h"
  28. #include "brush_select.h"
  29. #include "gimpbrushlist.h"
  30.  
  31. static ProcRecord brushes_popup_proc;
  32. static ProcRecord brushes_close_popup_proc;
  33. static ProcRecord brushes_set_popup_proc;
  34.  
  35. void
  36. register_brush_select_procs (void)
  37. {
  38.   procedural_db_register (&brushes_popup_proc);
  39.   procedural_db_register (&brushes_close_popup_proc);
  40.   procedural_db_register (&brushes_set_popup_proc);
  41. }
  42.  
  43. static BrushSelect *
  44. brush_get_brushselect (gchar *name)
  45. {
  46.   GSList *list;
  47.   BrushSelect *bsp;
  48.  
  49.   for (list = brush_active_dialogs; list; list = g_slist_next (list))
  50.     {
  51.       bsp = (BrushSelect *) list->data;
  52.  
  53.       if (bsp->callback_name && !strcmp (name, bsp->callback_name))
  54.     return bsp;
  55.     }
  56.  
  57.   return NULL;
  58. }
  59.  
  60. static Argument *
  61. brushes_popup_invoker (Argument *args)
  62. {
  63.   gboolean success = TRUE;
  64.   gchar *name;
  65.   gchar *title;
  66.   gchar *brush;
  67.   gdouble opacity;
  68.   gint32 spacing;
  69.   gint32 paint_mode;
  70.   ProcRecord *prec;
  71.   BrushSelect *newdialog;
  72.  
  73.   name = (gchar *) args[0].value.pdb_pointer;
  74.   if (name == NULL)
  75.     success = FALSE;
  76.  
  77.   title = (gchar *) args[1].value.pdb_pointer;
  78.   if (title == NULL)
  79.     success = FALSE;
  80.  
  81.   brush = (gchar *) args[2].value.pdb_pointer;
  82.  
  83.   opacity = args[3].value.pdb_float;
  84.  
  85.   spacing = args[4].value.pdb_int;
  86.  
  87.   paint_mode = args[5].value.pdb_int;
  88.   if (paint_mode < NORMAL_MODE || paint_mode > DIVIDE_MODE)
  89.     success = FALSE;
  90.  
  91.   if (success)
  92.     {
  93.       if ((prec = procedural_db_lookup (name)))
  94.     {
  95.       if (brush && strlen (brush))
  96.         newdialog = brush_select_new (title, brush, opacity, spacing,
  97.                       paint_mode);
  98.       else
  99.         newdialog = brush_select_new (title, NULL, 0.0, 0, 0);
  100.     
  101.       /* The callback procedure to run when brush changes */
  102.       newdialog->callback_name = g_strdup (name);
  103.     }
  104.       else
  105.     success = FALSE;
  106.     }
  107.  
  108.   return procedural_db_return_args (&brushes_popup_proc, success);
  109. }
  110.  
  111. static ProcArg brushes_popup_inargs[] =
  112. {
  113.   {
  114.     PDB_STRING,
  115.     "brush_callback",
  116.     "The callback PDB proc to call when brush selection is made"
  117.   },
  118.   {
  119.     PDB_STRING,
  120.     "popup_title",
  121.     "Title to give the brush popup window"
  122.   },
  123.   {
  124.     PDB_STRING,
  125.     "initial_brush",
  126.     "The name of the brush to set as the first selected"
  127.   },
  128.   {
  129.     PDB_FLOAT,
  130.     "opacity",
  131.     "The initial opacity of the brush"
  132.   },
  133.   {
  134.     PDB_INT32,
  135.     "spacing",
  136.     "The initial spacing of the brush (if < 0 then use brush default spacing)"
  137.   },
  138.   {
  139.     PDB_INT32,
  140.     "paint_mode",
  141.     "The initial paint mode: { NORMAL_MODE (0), DISSOLVE_MODE (1), BEHIND_MODE (2), MULTIPLY_MODE (3), SCREEN_MODE (4), OVERLAY_MODE (5), DIFFERENCE_MODE (6), ADDITION_MODE (7), SUBTRACT_MODE (8), DARKEN_ONLY_MODE (9), LIGHTEN_ONLY_MODE (10), HUE_MODE (11), SATURATION_MODE (12), COLOR_MODE (13), VALUE_MODE (14), DIVIDE_MODE (15) }"
  142.   }
  143. };
  144.  
  145. static ProcRecord brushes_popup_proc =
  146. {
  147.   "gimp_brushes_popup",
  148.   "Invokes the Gimp brush selection.",
  149.   "This procedure popups the brush selection dialog.",
  150.   "Andy Thomas",
  151.   "Andy Thomas",
  152.   "1998",
  153.   PDB_INTERNAL,
  154.   6,
  155.   brushes_popup_inargs,
  156.   0,
  157.   NULL,
  158.   { { brushes_popup_invoker } }
  159. };
  160.  
  161. static Argument *
  162. brushes_close_popup_invoker (Argument *args)
  163. {
  164.   gboolean success = TRUE;
  165.   gchar *name;
  166.   ProcRecord *prec;
  167.   BrushSelect *bsp;
  168.  
  169.   name = (gchar *) args[0].value.pdb_pointer;
  170.   if (name == NULL)
  171.     success = FALSE;
  172.  
  173.   if (success)
  174.     {
  175.       if ((prec = procedural_db_lookup (name)) &&
  176.       (bsp = brush_get_brushselect (name)))
  177.     {
  178.       if (GTK_WIDGET_VISIBLE (bsp->shell))
  179.         gtk_widget_hide (bsp->shell);
  180.     
  181.       /* Free memory if poping down dialog which is not the main one */
  182.       if (bsp != brush_select_dialog)
  183.         {
  184.           gtk_widget_destroy (bsp->shell);
  185.           brush_select_free (bsp);
  186.         }
  187.     }
  188.       else
  189.     success = FALSE;
  190.     }
  191.  
  192.   return procedural_db_return_args (&brushes_close_popup_proc, success);
  193. }
  194.  
  195. static ProcArg brushes_close_popup_inargs[] =
  196. {
  197.   {
  198.     PDB_STRING,
  199.     "brush_callback",
  200.     "The name of the callback registered for this popup"
  201.   }
  202. };
  203.  
  204. static ProcRecord brushes_close_popup_proc =
  205. {
  206.   "gimp_brushes_close_popup",
  207.   "Popdown the Gimp brush selection.",
  208.   "This procedure closes an opened brush selection dialog.",
  209.   "Andy Thomas",
  210.   "Andy Thomas",
  211.   "1998",
  212.   PDB_INTERNAL,
  213.   1,
  214.   brushes_close_popup_inargs,
  215.   0,
  216.   NULL,
  217.   { { brushes_close_popup_invoker } }
  218. };
  219.  
  220. static Argument *
  221. brushes_set_popup_invoker (Argument *args)
  222. {
  223.   gboolean success = TRUE;
  224.   gchar *name;
  225.   gchar *brush_name;
  226.   gdouble opacity;
  227.   gint32 spacing;
  228.   gint32 paint_mode;
  229.   ProcRecord *prec;
  230.   BrushSelect *bsp;
  231.  
  232.   name = (gchar *) args[0].value.pdb_pointer;
  233.   if (name == NULL)
  234.     success = FALSE;
  235.  
  236.   brush_name = (gchar *) args[1].value.pdb_pointer;
  237.   if (brush_name == NULL)
  238.     success = FALSE;
  239.  
  240.   opacity = args[2].value.pdb_float;
  241.  
  242.   spacing = args[3].value.pdb_int;
  243.  
  244.   paint_mode = args[4].value.pdb_int;
  245.   if (paint_mode < NORMAL_MODE || paint_mode > DIVIDE_MODE)
  246.     success = FALSE;
  247.  
  248.   if (success)
  249.     {
  250.       if ((prec = procedural_db_lookup (name)) &&
  251.       (bsp = brush_get_brushselect (name)))
  252.     {
  253.       GimpBrush *active = gimp_brush_list_get_brush (brush_list, brush_name);
  254.     
  255.       if (active)
  256.         {
  257.           /* Updating the context updates the widgets as well */
  258.     
  259.           gimp_context_set_brush (bsp->context, active);
  260.           gimp_context_set_opacity (bsp->context, opacity);
  261.           gimp_context_set_paint_mode (bsp->context, paint_mode);
  262.     
  263.           gtk_adjustment_set_value (GTK_ADJUSTMENT (bsp->spacing_data), spacing);
  264.         }
  265.       else
  266.         success = FALSE;
  267.     }
  268.       else
  269.     success = FALSE;
  270.     }
  271.  
  272.   return procedural_db_return_args (&brushes_set_popup_proc, success);
  273. }
  274.  
  275. static ProcArg brushes_set_popup_inargs[] =
  276. {
  277.   {
  278.     PDB_STRING,
  279.     "brush_callback",
  280.     "The name of the callback registered for this popup"
  281.   },
  282.   {
  283.     PDB_STRING,
  284.     "brush_name",
  285.     "The name of the brush to set as selected"
  286.   },
  287.   {
  288.     PDB_FLOAT,
  289.     "opacity",
  290.     "The initial opacity of the brush"
  291.   },
  292.   {
  293.     PDB_INT32,
  294.     "spacing",
  295.     "The initial spacing of the brush (if < 0 then use brush default spacing)"
  296.   },
  297.   {
  298.     PDB_INT32,
  299.     "paint_mode",
  300.     "The initial paint mode: { NORMAL_MODE (0), DISSOLVE_MODE (1), BEHIND_MODE (2), MULTIPLY_MODE (3), SCREEN_MODE (4), OVERLAY_MODE (5), DIFFERENCE_MODE (6), ADDITION_MODE (7), SUBTRACT_MODE (8), DARKEN_ONLY_MODE (9), LIGHTEN_ONLY_MODE (10), HUE_MODE (11), SATURATION_MODE (12), COLOR_MODE (13), VALUE_MODE (14), DIVIDE_MODE (15) }"
  301.   }
  302. };
  303.  
  304. static ProcRecord brushes_set_popup_proc =
  305. {
  306.   "gimp_brushes_set_popup",
  307.   "Sets the current brush selection in a popup.",
  308.   "Sets the current brush selection in a popup.",
  309.   "Andy Thomas",
  310.   "Andy Thomas",
  311.   "1998",
  312.   PDB_INTERNAL,
  313.   5,
  314.   brushes_set_popup_inargs,
  315.   0,
  316.   NULL,
  317.   { { brushes_set_popup_invoker } }
  318. };
  319.